﻿using System;
using GeoAPI.Geometries;

namespace YJKGridTopologyCal.Algorithm
{
	public class InteriorPointPoint
	{
		public InteriorPointPoint(IGeometry g)
		{
			this._centroid = g.Centroid.Coordinate;
			this.Add(g);
		}

		private void Add(IGeometry geom)
		{
			if (geom is IPoint)
			{
				this.Add(geom.Coordinate);
				return;
			}
			if (geom is IGeometryCollection)
			{
				foreach (IGeometry geom2 in ((IGeometryCollection)geom).Geometries)
				{
					this.Add(geom2);
				}
			}
		}

		private void Add(Coordinate point)
		{
			double num = point.Distance(this._centroid);
			if (num < this._minDistance)
			{
				this._interiorPoint = new Coordinate(point);
				this._minDistance = num;
			}
		}

		public Coordinate InteriorPoint
		{
			get
			{
				return this._interiorPoint;
			}
		}

		private readonly Coordinate _centroid;

		private double _minDistance = double.MaxValue;

		private Coordinate _interiorPoint;
	}
}
